﻿namespace Hidistro.UI.Web.AppShop
{
    using Hidistro.Core;
    using Hidistro.Membership.Context;
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;

    public class AppLogin : Page
    {
        protected HtmlForm form1;
        private string sessionId;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.sessionId = this.Page.Request.QueryString["sessionId"];
            if (!string.IsNullOrEmpty(this.sessionId))
            {
                Member userBySessionId = Users.GetUserBySessionId(this.sessionId) as Member;
                if ((userBySessionId != null) && !userBySessionId.IsAnonymous)
                {
                    HttpCookie cookie = new HttpCookie("Vshop-Member") {
                        Value = Globals.UrlEncode(userBySessionId.Username)
                    };
                    HttpContext.Current.Response.Cookies.Add(cookie);
                    HiContext.Current.User = userBySessionId;
                    userBySessionId.OnLogin();
                }
            }
            else
            {
                HttpCookie cookie2 = HiContext.Current.Context.Request.Cookies["Vshop-Member"];
                if ((cookie2 != null) && !string.IsNullOrEmpty(cookie2.Value))
                {
                    cookie2.Expires = DateTime.Now;
                    HttpContext.Current.Response.Cookies.Add(cookie2);
                }
            }
        }
    }
}

